package com.itcoon.cloud.framework.properties;/**
 * @author Athric Yu
 * 2024/11/12
 **/

import org.springframework.boot.context.properties.ConfigurationProperties;

import java.time.*;
import java.time.temporal.Temporal;

/**
 *
 *
 * @author Athric Yu
 * 2024/11/12
 **/
@ConfigurationProperties(prefix = "itcoon.global-config.temporal")
public class TemporalPatternConfigProperties {

    public TemporalSerialization<?,?>[] temporalSerializations = new TemporalSerialization[]{
            new TemporalSerialization<>(LocalDate.class, String.class, null, "yyyy-MM-dd"),
            new TemporalSerialization<>(LocalTime.class, String.class, null, "HH:mm:ss"),
            new TemporalSerialization<>(LocalDateTime.class, String.class, null, "yyyy-MM-dd HH:mm:ss"),
            new TemporalSerialization<>(ZonedDateTime.class, String.class, null,"yyyy-MM-dd HH:mm:ss")
    };

    public TemporalSerialization<?, ?>[] getTemporalSerializations() {
        return temporalSerializations;
    }

    public void setTemporalSerializations(TemporalSerialization<?, ?>[] temporalSerializations) {
        this.temporalSerializations = temporalSerializations;
    }

    public static class TemporalSerialization<S, T extends Temporal>{

        public TemporalSerialization() {
        }

        public TemporalSerialization(Class<T> temporalType, Class<S> serialType, String zoneId, String pattern) {
            this.temporalType = temporalType;
            this.serialType = serialType;
            this.zoneId = zoneId;
            this.pattern = pattern;
        }

        /**
         * 时间类型
         */
        private Class<T> temporalType;

        /**
         *
         *  序列化结果类型，支持 {@link Long} 和 {@link String}
         */
        private Class<S> serialType;

        /**
         *  ZoneId
         *  e.g +8:00
         */
        private String zoneId;

        /**
         * 格式化模板，对serialType为 {@link String}有效
         * e.g yyyy-MM-dd HH:mm:ss
         */
        private String pattern;

        public Class<T> getTemporalType() {
            return temporalType;
        }

        public void setTemporalType(Class<T> temporalType) {
            this.temporalType = temporalType;
        }

        public Class<S> getSerialType() {
            return serialType;
        }

        public void setSerialType(Class<S> serialType) {
            this.serialType = serialType;
        }

        public String getZoneId() {
            return zoneId;
        }

        public void setZoneId(String zoneId) {
            this.zoneId = zoneId;
        }

        public String getPattern() {
            return pattern;
        }

        public void setPattern(String pattern) {
            this.pattern = pattern;
        }
    }
}
